package com.shenhaofeng.app.http;


import com.shenhaofeng.app.http.okhttp.OkHttpCreator;
import com.shenhaofeng.app.http.request.Request;


/**
 * 网络客户端,封装了网络的请求实现
 * Created by Administrator on 2016/5/5.
 */
public class HttpClient implements Call.Factory {

    //调度器
    private Creator creator;


    public HttpClient(Creator creator) {
        creator(creator);
    }


    public HttpClient() {
        this(new OkHttpCreator());
    }


    /**
     * 配置一个调度器,HttpClient的请求实际上是由它执行的，通过调度器可以控制请求的运行
     *
     * @param creator
     */
    public void creator(Creator creator) {
        this.creator = creator;
        if (this.creator == null) {
            this.creator = new OkHttpCreator();
        }
    }


    @Override
    public Call newCall(Request request) {
        return creator().call(this, request);
    }


    public Creator creator() {
        return creator;
    }


}
